<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
  <title>get_page_id (MysqlLoader)</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
</head>
<body class="standalone-code">
  <pre><span class="ruby-comment cmt"># File etl/mysql.rb, line 129</span>
  <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">get_page_id</span>(<span class="ruby-identifier">dto</span>,<span class="ruby-identifier">source_id</span>)
    <span class="ruby-keyword kw">begin</span>
      <span class="ruby-identifier">stmt</span> = <span class="ruby-ivar">@conn</span>.<span class="ruby-identifier">prepare</span>(<span class="ruby-value str">&quot;SELECT id FROM pages WHERE url=? AND source_id=?&quot;</span>)
      <span class="ruby-identifier">stmt</span>.<span class="ruby-identifier">execute</span>(<span class="ruby-identifier">dto</span>.<span class="ruby-identifier">url</span>, <span class="ruby-identifier">source_id</span>)
      <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">stmt</span>.<span class="ruby-identifier">num_rows</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span>
        <span class="ruby-identifier">id</span> = <span class="ruby-identifier">stmt</span>.<span class="ruby-identifier">fetch</span>[<span class="ruby-value">0</span>]
      <span class="ruby-keyword kw">else</span>
        <span class="ruby-identifier">stmt</span>.<span class="ruby-identifier">close</span> <span class="ruby-comment cmt"># close the previous statement</span>
        <span class="ruby-identifier">stmt</span> = <span class="ruby-ivar">@conn</span>.<span class="ruby-identifier">prepare</span>(<span class="ruby-value str">&quot;INSERT INTO pages (url,source_id) VALUES (?,?)&quot;</span>)
        <span class="ruby-identifier">stmt</span>.<span class="ruby-identifier">execute</span>(<span class="ruby-identifier">dto</span>.<span class="ruby-identifier">url</span>,<span class="ruby-identifier">source_id</span>)
        <span class="ruby-identifier">id</span> = <span class="ruby-identifier">stmt</span>.<span class="ruby-identifier">insert_id</span>
      <span class="ruby-keyword kw">end</span>      
      <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">id</span>
    <span class="ruby-keyword kw">ensure</span>
      <span class="ruby-identifier">stmt</span>.<span class="ruby-identifier">close</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">stmt</span>
    <span class="ruby-keyword kw">end</span>
  <span class="ruby-keyword kw">end</span></pre>
</body>
</html>